package com.wcards.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcards.config.R;
import com.wcards.dto.AnimalDTO;
import com.wcards.entity.AnimalInfo;
import com.wcards.entity.CommentInfo;
import com.wcards.service.AnimalInfoService;
import com.wcards.service.CommentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author q'y
 */
@Api("动物模块")
@RestController
@Slf4j
@RequestMapping("/animal")
public class AnimalController {
    @Autowired
    private AnimalInfoService animalInfoService;
    @Autowired
    private CommentInfoService commentInfoService;
    //动物列表获取||动物查询

    @ApiOperation("根据编号获取动物")
    @GetMapping("getAnimalByNumber")
    public R<AnimalInfo> getAnimalByNumber(@ApiParam(value = "查询的编号") @RequestParam Integer animalNumber)
    {
        return animalInfoService.getAnimalByNumber(animalNumber);
    }

    @ApiOperation("查询动物")
    @PostMapping("queryAnimal")
    public R<Page<AnimalInfo>> getAnimalList(@ApiParam(value = "分页大小及查询的条件")@RequestBody AnimalDTO animalDTO)
    {
        return animalInfoService.getAnimalList(animalDTO);
    }

    @ApiOperation("添加动物")
    @PostMapping("addAnimal")
    public R<String> addAnimal(@ApiParam(value = "添加动物的信息",required = true) @RequestBody AnimalInfo animalInfo)
    {

        return animalInfoService.addAnimal(animalInfo);
    }
    @ApiOperation("删除动物")
    @DeleteMapping ("deleteAnimal")
    public R<String> deleteAnimal(@ApiParam(value = "要删除动物的编号",required = true)@RequestParam Integer animalNumbers)
    {
        return animalInfoService.deleteAnimal(animalNumbers);
    }

    @ApiOperation("修改动物")
    @PutMapping("updateAnimal")
    public R<String> updateAnimal(@ApiParam(value = "需要修改的动物实体信息必须包括ID",required = true)@RequestBody AnimalInfo animalInfo)
    {
        return animalInfoService.updateAnimal(animalInfo);
    }

    @ApiOperation("发布评论")
    @PostMapping("postComment")
    public R<String> postComment(@ApiParam(value = "评论的动物编号，发送评论的用户ID，评论的内容",required = true)Integer animalNumbers,Integer userId, String commentContent)
    {
        return commentInfoService.postComment(animalNumbers,userId,commentContent);
    }

    @ApiOperation("根据动物编号查看评论")
    @GetMapping("getCommentByAnimalNumbers")
    public R<Page<CommentInfo>> getCommentByAnimalNumbers(@ApiParam(value = "要查看评论的动物编号",required = true)@RequestParam Integer animalNumbers,Integer pageSize,Integer pageNumbers)
    {
        return commentInfoService.getCommentByAnimalNumbers(animalNumbers,pageSize,pageNumbers);
    }

    @ApiOperation("根据用户ID查看评论")
    @GetMapping("getCommentByUserId")
    public R<Page<CommentInfo>> getCommentByUserId(@ApiParam(value = "用户ID",required = true)Integer userId,Integer pageSize,Integer pageNumbers)
    {
        return commentInfoService.getCommentByUserId(userId,pageSize,pageNumbers);
    }

    @ApiOperation("修改评论")
    @PutMapping("updateComment")
    public R<String> updateComment(@ApiParam(value = "评论的编号及内容",required = true)Integer commentNumbers,String commentContent)
    {
        return commentInfoService.updateComment(commentNumbers,commentContent);
    }
    @ApiOperation("删除评论")
    @DeleteMapping("deleteComment")
    public R<String> deleteComment(@ApiParam(value = "需要删除的评论编号",required = true)Integer commentNumbers)
    {
        return commentInfoService.deleteComment(commentNumbers);
    }

}
